package org.example.myleet.p899;

import java.util.Arrays;

public class Solution {
    public String orderlyQueue(String s, int k) {
        if (k == 1) {
            String ss = s + s;
            String res = ss.substring(0, s.length());
            for (int i = 1; i < s.length(); ++i) {
                String si = ss.substring(i, i + s.length());
                if (si.compareTo(res) < 0) {
                    res = si;
                }
            }
            return res;
        }
        char[] charArr = s.toCharArray();
        Arrays.sort(charArr);
        return new String(charArr);
    }
}
